﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A75父子类型转换
{
    class Program
    {
        static void Main(string[] args)
        {
            Dog dog= new Dog();

            Animal a1 = dog;//狗一定是动物

            //以下是父转子两种方式(动物不一定是狗)
            Dog do1 = a1 as Dog;
            Dog do2 = (Dog)a1 ;

            //区别:
            Cat c1 = a1 as Cat;//返回null
            Cat c2 = (Cat)a1;//抛异常
        }
    }

    class Animal
    {

    }
    class Dog:Animal
    {

    }
    class Cat:Animal
    {

    }
}
